package com.ylbh.modules.goods.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.goods.vo.GoodsServiceVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.goods.service.GoodsClassService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 商品服务
 * @author: czx
 * @date: 2019/10/09 14:15
 */
@RestController
@RequestMapping("service")
public class ShoppingGoodsServiceController {

    @Autowired
    private GoodsClassService goodsClassService;

    @ApiOperation("商品服务列表")
    @GetMapping("queryGoodsServiceList")
//    @RequiresPermissions("service:queryGoodsServiceList")
    public CommonResult queryGoodsServiceList(PageDTO pageDTO) {
        PageUtils page = goodsClassService.queryGoodsServiceList(pageDTO);
        return Ref.ok(page);
    }

    @ApiOperation("商品服务详情")
    @GetMapping("getGoodsServiceInfoById/{id}")
    @RequiresPermissions("service:getGoodsServiceInfoById")
    public CommonResult getGoodsServiceInfoById(@PathVariable String id) {
        GoodsServiceVO vo = goodsClassService.getGoodsServiceInfoById(id);
        return Ref.ok(vo);
    }

    @SysLog("修改商品服务信息")
    @ApiOperation("修改商品服务信息")
    @PostMapping("modifyGoodsServiceDetailsById")
    @RequiresPermissions("service:modifyGoodsServiceDetailsById")
    public CommonResult modifyGoodsServiceDetailsById(@RequestBody GoodsServiceVO goodsService) {
        goodsClassService.modifyGoodsServiceDetailsById(goodsService);
        return Ref.ok();
    }

    @SysLog("删除商品服务")
    @ApiOperation("删除商品服务")
    @PostMapping("removeGoodsServiceByIds")
    @RequiresPermissions("service:removeGoodsServiceByIds")
    public CommonResult removeGoodsServiceByIds(@RequestBody String[] ids) {
        goodsClassService.removeGoodsServiceByIds(Arrays.asList(ids));
        return Ref.ok();
    }

    @SysLog("新增商品服务")
    @ApiOperation("新增商品服务")
    @PostMapping("addGoodsService")
    @RequiresPermissions("service:addGoodsService")
    public CommonResult addGoodsService(@RequestBody GoodsServiceVO goodsService) {
        goodsClassService.addGoodsService(goodsService);
        return Ref.ok();
    }

    @RequestMapping("queryHNDetails")
    public CommonResult queryHNDetails() {
        List<String> list = goodsClassService.queryHNDetails();
        return Ref.ok(list);
    }
}
